package com.master.demo.example.controller;

import com.master.common.annotation.IgnoreAuth;
import com.master.common.api.QueryDTO;
import com.master.common.api.ResponseInfo;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 接受不同请求方式
 * Get与Delete同理
 *
 * @author: Yang
 * @date: 2022/1/7
 * @version: 1.0.0
 * Copyright Ⓒ 2021 恒翔 Computer Corporation Limited All rights reserved.
 */
@RequestMapping("request")
public class GetController {

    /**
     * 根据单个id(路径参数)获取用户信息Demo
     *
     * @author: Yang
     * @date: 2024/1/16
     * @version: 1.0.0
     */
    @GetMapping(value = "/{id}")
    public ResponseInfo getUserByPath(@PathVariable(name = "id") Long id) {
        return ResponseInfo.success(id);
    }

    /**
     * 根据id和名称(路径参数)获取用户信息Demo
     *
     * @author: Yang
     * @date: 2021/1/7
     * @version: 1.0.0
     */
    @GetMapping(value = "/{id}/{name}")
    public ResponseInfo getUserByPath(@PathVariable(name = "id") Long id, @PathVariable(name = "name") String name) {
        String result = "id:" + id + "name:" + name;
        return ResponseInfo.success(result);
    }


    /**
     * 多参数组合查询用户信息demo(注解)
     *
     * @author: Yang
     * @date: 2021/1/7
     * @version: 1.0.0
     */
    @GetMapping(value = "/")
    public ResponseInfo getUserByParam(@RequestParam(name = "id") Long id, @RequestParam(name = "name") String name) {
        Map<String, Object> result = new HashMap<>(16);
        result.put("name", name);
        result.put("id", id);
        return ResponseInfo.success(result);
    }

    /**
     * 多参数组合查询用户信息demo(对象加参数接收)
     *
     * @author: Yang
     * @date: 2021/1/7
     * @version: 1.0.0
     */
    @GetMapping(value = "/query")
    public ResponseInfo getUserByParam(QueryDTO query, String name) {
        Map<String, Object> result = new HashMap<>(16);
        result.put("name", name);
        result.put("query", query);
        return ResponseInfo.success(result);
    }

    /**
     * 根据id(路径参数)和多参数组合查询用户信息demo(加上注解)
     *
     * @author: Yang
     * @date: 2021/1/7
     * @version: 1.0.0
     */
    @GetMapping(value = "/query/{id}")
    @IgnoreAuth
    public ResponseInfo getUserByParam(@PathVariable(name = "id") Long id, @ModelAttribute QueryDTO query, @RequestParam String name) {
        Map<String, Object> result = new HashMap<>(16);
        result.put("id", id);
        result.put("name", name);
        result.put("query", query);
        return ResponseInfo.success(result);
    }

    /**
     * 根据id(路径参数)和多参数组合查询用户信息demo(不加注解)
     *
     * @author: Yang
     * @date: 2021/1/7
     * @version: 1.0.0
     */
    @GetMapping(value = "/query/{id}")
    public ResponseInfo getUser(@PathVariable(name = "id") Long id, QueryDTO query, String name) {
        Map<String, Object> result = new HashMap<>(16);
        result.put("id", id);
        result.put("name", name);
        result.put("query", query);
        return ResponseInfo.success(result);
    }

}
